<?php

namespace Plugin\Message\Listener;

use Common\Common;
use Hyperf\Event\Annotation\Listener;
use Hyperf\Event\Contract\ListenerInterface;
use Plugin\Alarm\Event\WorkAcceptEvent;
use Plugin\Alarm\Event\WorkCreatedEvent;
use Plugin\Alarm\Event\WorkTransferEvent;
use Plugin\Message\Service\MessageService;
use Plugin\Organization\Repository\RdOrganizeUserStandRepository;

#[Listener]
class WorkListener implements ListenerInterface
{
    public function __construct(
        protected readonly RdOrganizeUserStandRepository $rdOrganizeUserStandRepository,
        protected readonly MessageService                $messageService
    )
    {
    }

    public function listen(): array
    {
        return [
            WorkCreatedEvent::class,
            WorkTransferEvent::class,
            WorkAcceptEvent::class
        ];
    }

    public function process(object $event): void
    {
        $this->messageService->createCallbackMessage(
            $event->getTargetUsers(),
            $event->getTitle(),
            $event->getMessage(),
            relatedId: $event->getRelatedId(),
            level: $event->getLevel()
        );
    }

}